<template>
	<view class="content">
		<u-form :model="form" ref="uForm" label-width="140">
			<u-form-item label="下单客户"><u-input v-model="form.custName" type="select" placeholder="下单客户" @click="custShow = true" /></u-form-item>
			<u-form-item label="下单时间" >
				<u-input v-model="form.orderTime" placeholder="下单时间" type="select" @click="dateShow = true" />
			</u-form-item>
			<u-form-item label="备注"><u-input v-model="form.biz" /></u-form-item>
			
			<view class="btn" @click="gotoCreate">确定</view>
		</u-form>
		<u-picker mode="time" :params="params" v-model="dateShow" @confirm="orderTimeChange"></u-picker>
		<u-select v-model="custShow" :list="custList" @confirm="custConfirm"></u-select>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				custList: [],
				dateShow: false,
				custShow: false,
				params: {
					year: true,
					month: true,
					day: true,
					hour: true,
					minute: true,
					second: true,
				},
				form: {
					custName: "",
					custId: "",
					orderTime: "",
					biz: ""
				},
				sjChooseCust: null
			};
		},
		onLoad(params) {
			console.log(params);
			if(params){
				this.sjChooseCust = params.cusCode
			}
			this.getCustList()
		},
		methods: {
			getCustList(){
				this.$api.user.getCusListByEmpId().then((res) => {
					console.log("res",res);
					this.custList = res.map(item => {
						return {
							value: item.custCode,
							label: item.custName
						}
					})
					this.form.custId = this.sjChooseCust
					if(this.sjChooseCust){
						this.form.custName = this.custList.find(item => item.value == this.sjChooseCust).label
					}
				})
			},
			custConfirm(val){
				this.form.custId = val[0].value;
				this.form.custName = val[0].label;
			},
			orderTimeChange(e){
				this.form.orderTime = e.year + '-' + e.month + '-' + e.day + ' ' + e.hour + ':' + e.minute + ':' + e.second;
			},
			gotoCreate() {
				if(!this.form.custName){
					uni.showToast({
						title: '请选择下单客户',
						duration: 2000,
						icon: "none"
					});
					return;
				}
				if(!this.form.orderTime){
					uni.showToast({
						title: '请选择下单时间',
						duration: 2000,
						icon: "none"
					});
					return;
				}
				uni.navigateTo({
					url: '/pages/order/create-order?custId=' + this.form.custId + '&custName=' + this.form.custName + '&orderTime=' + this.form.orderTime + '&biz=' + this.form.biz
				})
			}
		}
	}
</script>

<style lang="scss">
	.content{
		padding: 10rpx 30rpx;
		.btn{
			width: 100%;
			height: 80rpx;
			line-height: 80rpx;
			text-align: center;
			background-color: #007AFF;
			color: #FFFFFF;
			border-radius: 10rpx;
			margin-top: 20rpx;
		}
	}
</style>
